<?php
    require_once 'public/includes/functions.php';
    require_once 'models/container.php';
    
    class SearchController extends functions {
        
        var $container =null;
        var $breakPage = null;
        
        function __construct(){
            $this->container = new Container_Model();            
        }
        
        function listSearchContainer($currentPage){
            $row = 8;
            $list = array();
            if(empty($currentPage)|| $currentPage==1) $currentPage = 0;
            if(isset($_POST['contents'])){
                $name=$_POST['contents']; 
                $total = mysql_num_rows($this->container->ExecuteSQL("select * from container  where name like '%".$name."%'"));
                $start = $currentPage*$row;
                
                $sql = "select * from container  where name like '%{$name}%' LIMIT {$start},{$row}";
                $res = $this->container->ExecuteSQL($sql);
                if(mysql_num_rows($res)<=0){
            		//echo "<div id='noidung'>";
            		$list[] = "<div id='part'>
            		              <center><p class='search'> Không tìm thấy thông tin cần hiển thị</p></center>
            		          </div>";        		
            	}
                while($rs=mysql_fetch_array($res)){
    	           	$idbaiviet=$rs['ID'];
    			$name=$rs['name'];
    			$gioithieu=$rs['gioithieu'];
    			$anh=$rs['anh'];
    			$list[] = "<div id='noidung'>
    				        <div id='kqtim'>
                                <a href='./?rt=page&id={$idbaiviet}' >
                                    <h3 class='tieude'>{$name}</h3>
                                </a>    				            
    			                <p class='pKqtim'> 
                                    <a href='./?rt=page&id={$idbaiviet}' >
                                        <img src='upload/images/{$anh}' class='hinhbaiviet' width='100' height ='50'/>
                                    </a>
                                    {$gioithieu}  
                                </p>    				             
                            </div>					
    			         </div>";        
            			
                }
                $this->breakPage = $this->divPage($total,$currentPage,3,$row,'search','');    
            }
                    
            return $list;
        }
               
    }
    
    // thuc thi class
    $search = new SearchController();
    $search->show('search');
?>